import Validate from '/utils/validate';
import PageModel from '/utils/pagemodel';
let validateForm = new Validate();
let pagemodel = new PageModel();
const app = getApp();

Page({
  data: {
    carNum:``,
    showWarnTip: false,
    insuranceDateTip:'请选择车险有效期截止日期',
    enforceDateTip: '请选择交强险结束日期',
    desc:[
      {
        title: '取件时间',
        content: ['下单后一个工作日内，客服会按照客户所填写的预约取件时间，安排顺丰快递上门取件'],
      },
      {
        title: '所需材料',
        content: ['1. 车主身份证复印件正反面', '2. 有效期内交强险保单副本原件','3. 行驶证原件 + 复印件','4. 车辆登记证书复印件'],
      },
      {
        title: '代办时效',
        content: ['正常情况下3-5个工作日即可将资料、车辆合格证及绿标寄回'],
      },
    ]
  },
  onLoad(query) {
    // 页面加载
    // 初始化表单验证插件
    let bookInfo = my.getStorageSync({ key: "bookInfo" }).data;
    let carInfo = my.getStorageSync({ key: "carInfo" }).data;
    //console.log(carInfo)
    //console.log(bookInfo)

    this.setData({
      carNum: carInfo.car_num,
      orderNo: carInfo.orderNo,
      total: carInfo.total,
      orderStr:carInfo.order_str,
      carInfo: carInfo,
      bookInfo: bookInfo,
    });
    //console.log(this.data);
    
  },
  goToCarInfoPage(){
    //转至车辆信息页面
    my.navigateBack({
      delta: 1
    })
  },
  onUnload() {
    // 关闭程序
  },
  onSubmit(e) {
    this.setData({
      orderInfo: {
        bookInfo: this.data.bookInfo,
        carInfo: this.data.carInfo,
      }
    })
    
    //提交表单信息，唤起APP支付接口
    my.tradePay({
      orderStr: this.data.orderStr, //完整的支付参数拼接成的字符串，从服务端获取
      success: (res) => {
        //console.log('支付唤起成功')
        //console.log(res)
        if(res.resultCode==='9000'){
          //支付成功
          my.navigateTo({
            url: '/page/check-pay/pages/check-pay-success/check-pay-success'
          })
        }else{
          //其他情况（处理中、失败，中途取消、网络出错等）
          if(res.resultCode==='8000'){
            my.alert({
              content: '正在处理中，请稍后',
              buttonText: '我知道了'
            })
            return;
          }
          my.alert({
            content: '支付出现异常，请稍后重试',
            buttonText: '我知道了'
          })
        }
        
      },
      fail: (res) => {
        my.alert({
          content: JSON.stringify(res),
        });
      },
    });
  },
  getStorageSync() {
    var key = `carNum`;
    var data = this.data.carNum;
    //console.log('data: ', this.data);
    if (key.length === 0) {
      this.setData({
        keySync: key,
        dataSync: data,
      });

      my.alert({
        title: '同步读取数据失败',
        content: 'key 不能为空',
      });
    } else {
      let res = my.getStorageSync({ key: key });
      if (!res.error) {
        this.setData({
          'carNum': res.data,
        });
      }
    }
  },
  makePhoneCall01() {
    //拨打电话
     my.makePhoneCall({ number: '18823395242' });
  },
  makePhoneCall02() {
    //拨打电话
     my.makePhoneCall({ number: '0755-82562682' });
  },
  
});

